package com.saas.util;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;

public class DruidUtil {

    private static Env env = Env.getInstance();

    public static DataSource getDataSource()
    {
        try {
            DruidDataSource dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(env);

            dataSource.setUrl(env.getProperty("url"));
            dataSource.setUsername(env.getProperty("user"));
            dataSource.setPassword(env.getProperty("pass"));
            dataSource.setDriverClassName(env.getProperty("driver"));

            return dataSource;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
